Add JSON download modebar button - #7990
Conversation
|
All substantive CI checks are passing. The only failure is |
camdecoster
left a comment
There was a problem hiding this comment.
This looks good and is working in my testing. I'd like to move where the button gets added and add a success message for parity with the toImage button. Once that's done, I can approve and merge.
| | 'downloadJson' | ||
| // Other |
There was a problem hiding this comment.
I think it would be more appropriate to keep this under 'Other'.
| | 'downloadJson' | |
| // Other | |
| // Other | |
| | 'downloadJson' |
| modeBarButtons.downloadJson = { | ||
| name: 'downloadJson', | ||
| title: function (gd) { | ||
| return _(gd, 'Download plot as JSON'); | ||
| }, | ||
| icon: Icons.disk, | ||
| click: function (gd) { | ||
| Registry.call('downloadImage', gd, {format: 'full-json'}).catch(function () { | ||
| Lib.notifier(_(gd, 'Sorry, there was a problem downloading your JSON file!'), 'long', gd); | ||
| }); | ||
| } | ||
| }; |
There was a problem hiding this comment.
Let's add the success message along with the error message.
| modeBarButtons.downloadJson = { | |
| name: 'downloadJson', | |
| title: function (gd) { | |
| return _(gd, 'Download plot as JSON'); | |
| }, | |
| icon: Icons.disk, | |
| click: function (gd) { | |
| Registry.call('downloadImage', gd, {format: 'full-json'}).catch(function () { | |
| Lib.notifier(_(gd, 'Sorry, there was a problem downloading your JSON file!'), 'long', gd); | |
| }); | |
| } | |
| }; | |
| modeBarButtons.downloadJson = { | |
| name: 'downloadJson', | |
| title: (gd) => _(gd, 'Download plot as JSON'), | |
| icon: Icons.disk, | |
| click: (gd) => { | |
| Registry.call('downloadImage', gd, { format: 'full-json' }) | |
| .then((filename) => { | |
| Lib.notifier(_(gd, 'JSON download succeeded') + ' - ' + filename, 'long', gd); | |
| }) | |
| .catch(() => { | |
| Lib.notifier(_(gd, 'Sorry, there was a problem downloading your JSON file!'), 'long', gd); | |
| }); | |
| } | |
| }; |
| // buttons common to all plot types | ||
| var commonGroup = ['toImage']; | ||
| if(context.showSendToCloud) commonGroup.push('sendChartToCloud'); | ||
| addGroup(commonGroup); | ||
|
|
There was a problem hiding this comment.
Let's move this section down and add a boolean to track if the button should be included.
| let addDownloadJson = false; |
| enableHover('hoverClosest3d'); | ||
| enableHover('hoverClosestPie'); | ||
| } else if(b === 'downloadjson') { | ||
| newList.push(modeBarButtons.downloadJson); |
There was a problem hiding this comment.
| newList.push(modeBarButtons.downloadJson); | |
| addDownloadJson = true; |
| buttonsToAdd = newList; | ||
| } | ||
|
|
||
| addGroup(dragModeGroup); |
There was a problem hiding this comment.
By moving this down, we can place the downloadJson button next to the download image button, which makes more sense to me.
| // buttons common to all plot types | |
| const commonGroup = ['toImage']; | |
| if (addDownloadJson) commonGroup.push('downloadJson'); | |
| if (context.showSendToCloud) commonGroup.push('sendChartToCloud'); | |
| addGroup(commonGroup); | |
| addGroup(dragModeGroup); |
What does this PR do?
Adds an opt-in
downloadJsonmodebar button for exporting the current Plotly figure as JSON.The button can be enabled through:
or through
layout.modebar.add.It uses Plotly's existing
full-jsonexport pipeline, preserving the established serialization behavior for figure data, layout, config, typed arrays, and version metadata. Download failures are reported through the existing Plotly notifier.This replaces #7963, which GitHub closed after its base branch was deleted.
Closes #7917
Testing
npm run test-jasmine -- modebar --nowatch(103 tests passed)npm run lintnpm run typechecknpm run test-syntaxnpm run schema-typegen-diff-checkgit diff --check